<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #cs {
        border: 1px solid #999;
      }
    </style>
  </head>
  <body>
    <canvas id="cs" width="400px" height="400px">您的浏览器不支持canvas</canvas>
  </body>
  <script>
    var cs = document.getElementById("cs");
    if (cs.getContext("2d")) {
      var ctx = cs.getContext("2d");
      var img = new Image();
      // img.src = "./images/Canvas_backdrop.png";
      img.src = "./images/rhino.jpg";
      img.onload = function () {
        // 基本绘制
        // ctx.drawImage(img,0,0)
        // 缩放
        // ctx.drawImage(img,10,10,300,400)
        // 生成切片
        ctx.drawImage(img, 100, 100, 150, 150, 100, 100, 150, 150);
      };
    } else {
      console.log("您的浏览器不支持canvas");
    }
  </script>
</html>
